package com.chinaway.mobile.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com.chinaway.base.BaseSpringJdbcDao;
import com.chinaway.mobile.dao.BalanceCounterDao;
import com.chinaway.mobile.model.Account;
import com.chinaway.mobile.model.BalanceCounter;
import com.chinaway.mobile.model.Sim;

public class BalanceCounterDaoJdbc extends BaseSpringJdbcDao<Sim, Long> implements BalanceCounterDao {
	

															
	private static String save = "insert into mobile_balance_count(createtime,message,count,mytype) values(?,?,?,?)";
	
	private static String find = "SELECT createtime,message,count,mytype  FROM mobile_balance_count  where createtime >= ? and createtime <= ? and mytype=?";
	
	ParameterizedRowMapper<BalanceCounter> balanceMapper = new ParameterizedRowMapper<BalanceCounter>()
	 {
		 public BalanceCounter mapRow(ResultSet rs, int rowNum) throws SQLException
		 {
			 Date createtime=rs.getDate(1);
			  String message = rs.getString(2);
			  int count = rs.getInt(3);
			  String mytype = rs.getString(4);
			 return  new BalanceCounter(createtime, message, count, mytype);
		 }
	 };
	 
	@Override
	public void save(BalanceCounter bc) {
		this.getSimpleJdbcTemplate().update(save, new Object[]{
				bc.getCreatetime(),
				bc.getMessage(),
				bc.getCount(),
				bc.getMytype()
		});
	}

	@Override
	public List<BalanceCounter> select(Date from, Date to, int type) {
		return (List<BalanceCounter>)getSimpleJdbcTemplate().query(find, balanceMapper, from,to,type);
	}

}
